package com.test.boot.http.rpc.client;

import com.test.boot.http.rpc.api.entity.User;
import com.test.boot.http.rpc.api.service.DemoService;
import com.test.boot.http.rpc.api.service.HelloService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.List;

/**
 * Created by hujianjun on 2015/12/4.
 */
@SpringBootApplication
public class Client {
    static Logger log = LoggerFactory.getLogger(Client.class);
//    static Log log = LogFactory.getLog(Client.class);

    public static ConfigurableApplicationContext context;

    public static void main(String[] args) throws InterruptedException {
        context = SpringApplication.run(Client.class, args);

//        for(String name:context.getBeanDefinitionNames()) {
//            System.out.println(name);
//        }
//
        DemoService demoService = context.getBean("demoService", DemoService.class);

        String r = demoService.testDemo("A");

        r += demoService.testDemo("B");
        r += demoService.testDemo("C");
        r += demoService.testDemo("D");

        log.info(r);

        HelloService helloService = context.getBean("helloService", HelloService.class);
        String ret = helloService.test("中国");
        log.info(ret);

        for(int i=0; i<100; i++) {
            String name = "名称"+i;
            User user = helloService.createUser(name, i);
            log.info("增加成功：" + user);
        }

        List<User> users = helloService.listUsers();
        log.info(users.toString());
    }
}
